package com.yyp.car.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yyp.car.Idao.IUserDao;
import com.yyp.car.Iservice.IUserService;
import com.yyp.car.model.User;
import com.yyp.exception.CarException;

@Service("userService")
public class UserService implements IUserService{

	@Resource(name="userDao")
	private IUserDao userDao;
	@Override
	public User login(String username,String password) {
		User user=userDao.findByUserName(username);
		if(user==null)
		{
			throw new CarException("用户名或密码错误");
		}else{
			if(!user.getPassword().equals(password))
			{
				throw new CarException("用户名或密码错误");
			}
		}
		return user;
	}

	@Override
	public User register(User user) {
		return userDao.add(user);
	}

	@Override
	public void update(User user) {
		userDao.update(user);
	}

	@Override
	public List<User> listTeacher() {
		return userDao.listTeacher();
	}

	@Override
	public void delete(int id) {
		userDao.delete(id);
		
	}

	@Override
	public User load(int id) {
		return userDao.load(id);
	}

	@Override
	public List<User> listStudent() {
		return userDao.listStudent();
	}

	@Override
	public User findById(int id) {
		return userDao.findById(id);
	}

	@Override
	public List<User> listStudentByTid(int tid) {
		return userDao.listStudentByTid(tid);
	}

	@Override
	public String findPassword(int id) {
		return userDao.findPassword(id);
	}

	@Override
	public void changePassword(int id, String password) {
		userDao.changePassword(id, password);
	}

	@Override
	public User findUser(String username) {
		return userDao.findByUserName(username);
	}

	@Override
	public List<User> listAllStudent() {
		return userDao.listAllStudent();
	}

	@Override
	public void blackStudent(int id) {
		userDao.blackStudent(id);
		
	}

	@Override
	public void whiteStudent(int id) {
		userDao.whiteStudent(id);
		
	}
}
